// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Cloud Logging API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_logging_v2::client::LoggingServiceV2;
/// let client = LoggingServiceV2::builder().build().await?;
/// // use `client` to make requests to the Cloud Logging API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Service for ingesting and querying logs.
///
/// # Configuration
///
/// To configure `LoggingServiceV2` use the `with_*` methods in the type returned
/// by [builder()][LoggingServiceV2::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://logging.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::logging_service_v_2::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::logging_service_v_2::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `LoggingServiceV2` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `LoggingServiceV2` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct LoggingServiceV2 {
    inner: std::sync::Arc<dyn super::stub::dynamic::LoggingServiceV2>,
}

impl LoggingServiceV2 {
    /// Returns a builder for [LoggingServiceV2].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_logging_v2::client::LoggingServiceV2;
    /// let client = LoggingServiceV2::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::logging_service_v_2::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::logging_service_v_2::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::LoggingServiceV2 + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::LoggingServiceV2>>
    {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::LoggingServiceV2> {
        super::transport::LoggingServiceV2::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::LoggingServiceV2> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::LoggingServiceV2::new)
    }

    /// Deletes all the log entries in a log for the _Default Log Bucket. The log
    /// reappears if it receives new entries. Log entries written shortly before
    /// the delete operation might not be deleted. Entries received after the
    /// delete operation with a timestamp before the operation will be deleted.
    pub fn delete_log(&self) -> super::builder::logging_service_v_2::DeleteLog {
        super::builder::logging_service_v_2::DeleteLog::new(self.inner.clone())
    }

    /// Writes log entries to Logging. This API method is the
    /// only way to send log entries to Logging. This method
    /// is used, directly or indirectly, by the Logging agent
    /// (fluentd) and all logging libraries configured to use Logging.
    /// A single request may contain log entries for a maximum of 1000
    /// different resources (projects, organizations, billing accounts or
    /// folders)
    pub fn write_log_entries(&self) -> super::builder::logging_service_v_2::WriteLogEntries {
        super::builder::logging_service_v_2::WriteLogEntries::new(self.inner.clone())
    }

    /// Lists log entries.  Use this method to retrieve log entries that originated
    /// from a project/folder/organization/billing account.  For ways to export log
    /// entries, see [Exporting
    /// Logs](https://cloud.google.com/logging/docs/export).
    pub fn list_log_entries(&self) -> super::builder::logging_service_v_2::ListLogEntries {
        super::builder::logging_service_v_2::ListLogEntries::new(self.inner.clone())
    }

    /// Lists the descriptors for monitored resource types used by Logging.
    pub fn list_monitored_resource_descriptors(
        &self,
    ) -> super::builder::logging_service_v_2::ListMonitoredResourceDescriptors {
        super::builder::logging_service_v_2::ListMonitoredResourceDescriptors::new(
            self.inner.clone(),
        )
    }

    /// Lists the logs in projects, organizations, folders, or billing accounts.
    /// Only logs that have entries are listed.
    pub fn list_logs(&self) -> super::builder::logging_service_v_2::ListLogs {
        super::builder::logging_service_v_2::ListLogs::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn list_operations(&self) -> super::builder::logging_service_v_2::ListOperations {
        super::builder::logging_service_v_2::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::logging_service_v_2::GetOperation {
        super::builder::logging_service_v_2::GetOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn cancel_operation(&self) -> super::builder::logging_service_v_2::CancelOperation {
        super::builder::logging_service_v_2::CancelOperation::new(self.inner.clone())
    }
}

/// Implements a client for the Cloud Logging API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_logging_v2::client::ConfigServiceV2;
/// let client = ConfigServiceV2::builder().build().await?;
/// // use `client` to make requests to the Cloud Logging API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Service for configuring sinks used to route log entries.
///
/// # Configuration
///
/// To configure `ConfigServiceV2` use the `with_*` methods in the type returned
/// by [builder()][ConfigServiceV2::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://logging.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::config_service_v_2::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::config_service_v_2::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `ConfigServiceV2` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `ConfigServiceV2` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct ConfigServiceV2 {
    inner: std::sync::Arc<dyn super::stub::dynamic::ConfigServiceV2>,
}

impl ConfigServiceV2 {
    /// Returns a builder for [ConfigServiceV2].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_logging_v2::client::ConfigServiceV2;
    /// let client = ConfigServiceV2::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::config_service_v_2::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::config_service_v_2::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::ConfigServiceV2 + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::ConfigServiceV2>>
    {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ConfigServiceV2> {
        super::transport::ConfigServiceV2::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ConfigServiceV2> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::ConfigServiceV2::new)
    }

    /// Lists log buckets.
    pub fn list_buckets(&self) -> super::builder::config_service_v_2::ListBuckets {
        super::builder::config_service_v_2::ListBuckets::new(self.inner.clone())
    }

    /// Gets a log bucket.
    pub fn get_bucket(&self) -> super::builder::config_service_v_2::GetBucket {
        super::builder::config_service_v_2::GetBucket::new(self.inner.clone())
    }

    /// Creates a log bucket asynchronously that can be used to store log entries.
    ///
    /// After a bucket has been created, the bucket's location cannot be changed.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn create_bucket_async(&self) -> super::builder::config_service_v_2::CreateBucketAsync {
        super::builder::config_service_v_2::CreateBucketAsync::new(self.inner.clone())
    }

    /// Updates a log bucket asynchronously.
    ///
    /// If the bucket has a `lifecycle_state` of `DELETE_REQUESTED`, then
    /// `FAILED_PRECONDITION` will be returned.
    ///
    /// After a bucket has been created, the bucket's location cannot be changed.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn update_bucket_async(&self) -> super::builder::config_service_v_2::UpdateBucketAsync {
        super::builder::config_service_v_2::UpdateBucketAsync::new(self.inner.clone())
    }

    /// Creates a log bucket that can be used to store log entries. After a bucket
    /// has been created, the bucket's location cannot be changed.
    pub fn create_bucket(&self) -> super::builder::config_service_v_2::CreateBucket {
        super::builder::config_service_v_2::CreateBucket::new(self.inner.clone())
    }

    /// Updates a log bucket.
    ///
    /// If the bucket has a `lifecycle_state` of `DELETE_REQUESTED`, then
    /// `FAILED_PRECONDITION` will be returned.
    ///
    /// After a bucket has been created, the bucket's location cannot be changed.
    pub fn update_bucket(&self) -> super::builder::config_service_v_2::UpdateBucket {
        super::builder::config_service_v_2::UpdateBucket::new(self.inner.clone())
    }

    /// Deletes a log bucket.
    ///
    /// Changes the bucket's `lifecycle_state` to the `DELETE_REQUESTED` state.
    /// After 7 days, the bucket will be purged and all log entries in the bucket
    /// will be permanently deleted.
    pub fn delete_bucket(&self) -> super::builder::config_service_v_2::DeleteBucket {
        super::builder::config_service_v_2::DeleteBucket::new(self.inner.clone())
    }

    /// Undeletes a log bucket. A bucket that has been deleted can be undeleted
    /// within the grace period of 7 days.
    pub fn undelete_bucket(&self) -> super::builder::config_service_v_2::UndeleteBucket {
        super::builder::config_service_v_2::UndeleteBucket::new(self.inner.clone())
    }

    /// Lists views on a log bucket.
    pub fn list_views(&self) -> super::builder::config_service_v_2::ListViews {
        super::builder::config_service_v_2::ListViews::new(self.inner.clone())
    }

    /// Gets a view on a log bucket..
    pub fn get_view(&self) -> super::builder::config_service_v_2::GetView {
        super::builder::config_service_v_2::GetView::new(self.inner.clone())
    }

    /// Creates a view over log entries in a log bucket. A bucket may contain a
    /// maximum of 30 views.
    pub fn create_view(&self) -> super::builder::config_service_v_2::CreateView {
        super::builder::config_service_v_2::CreateView::new(self.inner.clone())
    }

    /// Updates a view on a log bucket. This method replaces the following fields
    /// in the existing view with values from the new view: `filter`.
    /// If an `UNAVAILABLE` error is returned, this indicates that system is not in
    /// a state where it can update the view. If this occurs, please try again in a
    /// few minutes.
    pub fn update_view(&self) -> super::builder::config_service_v_2::UpdateView {
        super::builder::config_service_v_2::UpdateView::new(self.inner.clone())
    }

    /// Deletes a view on a log bucket.
    /// If an `UNAVAILABLE` error is returned, this indicates that system is not in
    /// a state where it can delete the view. If this occurs, please try again in a
    /// few minutes.
    pub fn delete_view(&self) -> super::builder::config_service_v_2::DeleteView {
        super::builder::config_service_v_2::DeleteView::new(self.inner.clone())
    }

    /// Lists sinks.
    pub fn list_sinks(&self) -> super::builder::config_service_v_2::ListSinks {
        super::builder::config_service_v_2::ListSinks::new(self.inner.clone())
    }

    /// Gets a sink.
    pub fn get_sink(&self) -> super::builder::config_service_v_2::GetSink {
        super::builder::config_service_v_2::GetSink::new(self.inner.clone())
    }

    /// Creates a sink that exports specified log entries to a destination. The
    /// export of newly-ingested log entries begins immediately, unless the sink's
    /// `writer_identity` is not permitted to write to the destination. A sink can
    /// export log entries only from the resource owning the sink.
    pub fn create_sink(&self) -> super::builder::config_service_v_2::CreateSink {
        super::builder::config_service_v_2::CreateSink::new(self.inner.clone())
    }

    /// Updates a sink. This method replaces the following fields in the existing
    /// sink with values from the new sink: `destination`, and `filter`.
    ///
    /// The updated sink might also have a new `writer_identity`; see the
    /// `unique_writer_identity` field.
    pub fn update_sink(&self) -> super::builder::config_service_v_2::UpdateSink {
        super::builder::config_service_v_2::UpdateSink::new(self.inner.clone())
    }

    /// Deletes a sink. If the sink has a unique `writer_identity`, then that
    /// service account is also deleted.
    pub fn delete_sink(&self) -> super::builder::config_service_v_2::DeleteSink {
        super::builder::config_service_v_2::DeleteSink::new(self.inner.clone())
    }

    /// Asynchronously creates a linked dataset in BigQuery which makes it possible
    /// to use BigQuery to read the logs stored in the log bucket. A log bucket may
    /// currently only contain one link.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn create_link(&self) -> super::builder::config_service_v_2::CreateLink {
        super::builder::config_service_v_2::CreateLink::new(self.inner.clone())
    }

    /// Deletes a link. This will also delete the corresponding BigQuery linked
    /// dataset.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_link(&self) -> super::builder::config_service_v_2::DeleteLink {
        super::builder::config_service_v_2::DeleteLink::new(self.inner.clone())
    }

    /// Lists links.
    pub fn list_links(&self) -> super::builder::config_service_v_2::ListLinks {
        super::builder::config_service_v_2::ListLinks::new(self.inner.clone())
    }

    /// Gets a link.
    pub fn get_link(&self) -> super::builder::config_service_v_2::GetLink {
        super::builder::config_service_v_2::GetLink::new(self.inner.clone())
    }

    /// Lists all the exclusions on the _Default sink in a parent resource.
    pub fn list_exclusions(&self) -> super::builder::config_service_v_2::ListExclusions {
        super::builder::config_service_v_2::ListExclusions::new(self.inner.clone())
    }

    /// Gets the description of an exclusion in the _Default sink.
    pub fn get_exclusion(&self) -> super::builder::config_service_v_2::GetExclusion {
        super::builder::config_service_v_2::GetExclusion::new(self.inner.clone())
    }

    /// Creates a new exclusion in the _Default sink in a specified parent
    /// resource. Only log entries belonging to that resource can be excluded. You
    /// can have up to 10 exclusions in a resource.
    pub fn create_exclusion(&self) -> super::builder::config_service_v_2::CreateExclusion {
        super::builder::config_service_v_2::CreateExclusion::new(self.inner.clone())
    }

    /// Changes one or more properties of an existing exclusion in the _Default
    /// sink.
    pub fn update_exclusion(&self) -> super::builder::config_service_v_2::UpdateExclusion {
        super::builder::config_service_v_2::UpdateExclusion::new(self.inner.clone())
    }

    /// Deletes an exclusion in the _Default sink.
    pub fn delete_exclusion(&self) -> super::builder::config_service_v_2::DeleteExclusion {
        super::builder::config_service_v_2::DeleteExclusion::new(self.inner.clone())
    }

    /// Gets the Logging CMEK settings for the given resource.
    ///
    /// Note: CMEK for the Log Router can be configured for Google Cloud projects,
    /// folders, organizations and billing accounts. Once configured for an
    /// organization, it applies to all projects and folders in the Google Cloud
    /// organization.
    ///
    /// See [Enabling CMEK for Log
    /// Router](https://cloud.google.com/logging/docs/routing/managed-encryption)
    /// for more information.
    pub fn get_cmek_settings(&self) -> super::builder::config_service_v_2::GetCmekSettings {
        super::builder::config_service_v_2::GetCmekSettings::new(self.inner.clone())
    }

    /// Updates the Log Router CMEK settings for the given resource.
    ///
    /// Note: CMEK for the Log Router can currently only be configured for Google
    /// Cloud organizations. Once configured, it applies to all projects and
    /// folders in the Google Cloud organization.
    ///
    /// [UpdateCmekSettings][google.logging.v2.ConfigServiceV2.UpdateCmekSettings]
    /// will fail if 1) `kms_key_name` is invalid, or 2) the associated service
    /// account does not have the required
    /// `roles/cloudkms.cryptoKeyEncrypterDecrypter` role assigned for the key, or
    /// 3) access to the key is disabled.
    ///
    /// See [Enabling CMEK for Log
    /// Router](https://cloud.google.com/logging/docs/routing/managed-encryption)
    /// for more information.
    ///
    /// [google.logging.v2.ConfigServiceV2.UpdateCmekSettings]: crate::client::ConfigServiceV2::update_cmek_settings
    pub fn update_cmek_settings(&self) -> super::builder::config_service_v_2::UpdateCmekSettings {
        super::builder::config_service_v_2::UpdateCmekSettings::new(self.inner.clone())
    }

    /// Gets the Log Router settings for the given resource.
    ///
    /// Note: Settings for the Log Router can be get for Google Cloud projects,
    /// folders, organizations and billing accounts. Currently it can only be
    /// configured for organizations. Once configured for an organization, it
    /// applies to all projects and folders in the Google Cloud organization.
    ///
    /// See [Enabling CMEK for Log
    /// Router](https://cloud.google.com/logging/docs/routing/managed-encryption)
    /// for more information.
    pub fn get_settings(&self) -> super::builder::config_service_v_2::GetSettings {
        super::builder::config_service_v_2::GetSettings::new(self.inner.clone())
    }

    /// Updates the Log Router settings for the given resource.
    ///
    /// Note: Settings for the Log Router can currently only be configured for
    /// Google Cloud organizations. Once configured, it applies to all projects and
    /// folders in the Google Cloud organization.
    ///
    /// [UpdateSettings][google.logging.v2.ConfigServiceV2.UpdateSettings]
    /// will fail if 1) `kms_key_name` is invalid, or 2) the associated service
    /// account does not have the required
    /// `roles/cloudkms.cryptoKeyEncrypterDecrypter` role assigned for the key, or
    /// 3) access to the key is disabled. 4) `location_id` is not supported by
    /// Logging. 5) `location_id` violate OrgPolicy.
    ///
    /// See [Enabling CMEK for Log
    /// Router](https://cloud.google.com/logging/docs/routing/managed-encryption)
    /// for more information.
    ///
    /// [google.logging.v2.ConfigServiceV2.UpdateSettings]: crate::client::ConfigServiceV2::update_settings
    pub fn update_settings(&self) -> super::builder::config_service_v_2::UpdateSettings {
        super::builder::config_service_v_2::UpdateSettings::new(self.inner.clone())
    }

    /// Copies a set of log entries from a log bucket to a Cloud Storage bucket.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn copy_log_entries(&self) -> super::builder::config_service_v_2::CopyLogEntries {
        super::builder::config_service_v_2::CopyLogEntries::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn list_operations(&self) -> super::builder::config_service_v_2::ListOperations {
        super::builder::config_service_v_2::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::config_service_v_2::GetOperation {
        super::builder::config_service_v_2::GetOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn cancel_operation(&self) -> super::builder::config_service_v_2::CancelOperation {
        super::builder::config_service_v_2::CancelOperation::new(self.inner.clone())
    }
}

/// Implements a client for the Cloud Logging API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_logging_v2::client::MetricsServiceV2;
/// let client = MetricsServiceV2::builder().build().await?;
/// // use `client` to make requests to the Cloud Logging API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Service for configuring logs-based metrics.
///
/// # Configuration
///
/// To configure `MetricsServiceV2` use the `with_*` methods in the type returned
/// by [builder()][MetricsServiceV2::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://logging.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::metrics_service_v_2::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::metrics_service_v_2::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `MetricsServiceV2` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `MetricsServiceV2` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct MetricsServiceV2 {
    inner: std::sync::Arc<dyn super::stub::dynamic::MetricsServiceV2>,
}

impl MetricsServiceV2 {
    /// Returns a builder for [MetricsServiceV2].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_logging_v2::client::MetricsServiceV2;
    /// let client = MetricsServiceV2::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::metrics_service_v_2::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::metrics_service_v_2::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::MetricsServiceV2 + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::MetricsServiceV2>>
    {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::MetricsServiceV2> {
        super::transport::MetricsServiceV2::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::MetricsServiceV2> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::MetricsServiceV2::new)
    }

    /// Lists logs-based metrics.
    pub fn list_log_metrics(&self) -> super::builder::metrics_service_v_2::ListLogMetrics {
        super::builder::metrics_service_v_2::ListLogMetrics::new(self.inner.clone())
    }

    /// Gets a logs-based metric.
    pub fn get_log_metric(&self) -> super::builder::metrics_service_v_2::GetLogMetric {
        super::builder::metrics_service_v_2::GetLogMetric::new(self.inner.clone())
    }

    /// Creates a logs-based metric.
    pub fn create_log_metric(&self) -> super::builder::metrics_service_v_2::CreateLogMetric {
        super::builder::metrics_service_v_2::CreateLogMetric::new(self.inner.clone())
    }

    /// Creates or updates a logs-based metric.
    pub fn update_log_metric(&self) -> super::builder::metrics_service_v_2::UpdateLogMetric {
        super::builder::metrics_service_v_2::UpdateLogMetric::new(self.inner.clone())
    }

    /// Deletes a logs-based metric.
    pub fn delete_log_metric(&self) -> super::builder::metrics_service_v_2::DeleteLogMetric {
        super::builder::metrics_service_v_2::DeleteLogMetric::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn list_operations(&self) -> super::builder::metrics_service_v_2::ListOperations {
        super::builder::metrics_service_v_2::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::metrics_service_v_2::GetOperation {
        super::builder::metrics_service_v_2::GetOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn cancel_operation(&self) -> super::builder::metrics_service_v_2::CancelOperation {
        super::builder::metrics_service_v_2::CancelOperation::new(self.inner.clone())
    }
}
